<extend name="./Application/Admin/View/Layout/application.html"/>

<block name="content">
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">广告列表</strong> /
                    <small>AD list</small>
                </div>
            </div>

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{{:U('Advert/add')}}" class="am-btn am-btn-default"><span
                                    class="am-icon-plus"></span> 新增
                            </a>
                            <button type="button" class="am-btn am-btn-default del_all"><span class="am-icon-trash-o"></span> 删除
                            </button>
                        </div>
                    </div>
                </div>
                <form>
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-input-group am-input-group-sm">
                        <div class="am-input-group am-input-group-sm">
                            <input type="text" name="title" class="am-form-field" placeholder="按标题名称">
                            <span class="am-input-group-btn">
                            <button class="am-btn am-btn-default" type="submit">搜索</button>
                            <a href="{{:U('Advert/index')}}" class="am-btn am-btn-default">重置</a>
                            </span>
                        </div>
                        <!--<input type="text" class="am-form-field" name="title" placeholder="按标题名称">-->
                        <!--<span class="am-input-group-btn">-->
                            <!--<a class="am-btn am-btn-default" type="submit">搜索</a>-->
                            <!--<a href="{{:U('Advert/index')}}" class="am-btn am-btn-default">重置</a>-->
                        <!--</span>-->
                    </div>
                </div>
                </form>
            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <table class="am-table am-table-striped am-table-hover table-main">
                        <thead>
                        <tr>
                            <th class="table-check"><input type="checkbox" class="checked_all"/></th>
                            <th class="table-id">ID</th>
                            <th class="table-title">缩略图</th>
                            <th class="table-type">标题</th>
                            <th class="table-author am-hide-sm-only">广告地址</th>
                            <th class="table-date am-hide-sm-only">广告描述</th>
                            <th class="table-date am-hide-sm-only">排序</th>
                            <th class="table-set">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <volist name="adverts" id="advert">
                            <tr data-id="{{$advert.id}}">
                                <td><input type="checkbox"  name="checked_id[]" class="checked_id"  value="{{$advert.id}}"/></td>
                                <td class="am-hide-sm-only">{{$advert.id}}</td>
                                <td class="am-hide-sm-only">
                                    <img src="{{$advert.thumb}}" style="width:80px;height:60px;">
                                </td>
                                <td class="am-hide-sm-only">{{$advert.title}}</td>
                                <td class="am-hide-sm-only"><a href="#">{{$advert.url}}</a></td>
                                <td class="am-hide-sm-only">{{$advert.description}}</td>
                                <td>
                                    <input type="text" value="{{$advert.sort_order}}" style="width: 40px;">
                                </td>
                                <td>
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <a href="{{:U('edit', ['id'=>$advert[id]])}}"
                                               class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                    class="am-icon-pencil-square-o"></span> 编辑
                                            </a>
                                            <a href="{{:U('delete', ['id'=>$advert[id]])}}"
                                               class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only delete_one">
                                                <span class="am-icon-trash-o"></span> 删除
                                            </a>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </volist>
                        </tbody>
                    </table>
                    <div class="am-cf">
                        共 {{$count['adverts']}} 条记录
                        <div class="am-fr">
                            <ul class="am-pagination">
                                <!--<li class="am-disabled"><a href="#">«</a></li>-->
                                <!--<li class="am-active"><a href="#">1</a></li>-->
                                <!--<li><a href="#">2</a></li>-->
                                <!--<li><a href="#">3</a></li>-->
                                <!--<li><a href="#">4</a></li>-->
                                <!--<li><a href="#">5</a></li>-->
                                <!--<li><a href="#">»</a></li>-->
                                {{$page}}
                            </ul>
                        </div>
                    </div>
                    <hr/>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>
</block>
<block name="js">
    <script>
        $(function () {
            //全选/反选
            $('.checked_all').click(function () {
                $(':checkbox').prop("checked", this.checked);
            });
            //AJAX删除多条记录
            $(".del_all").click(function () {
                var length = $(".checked_id:checked").length;
                if (length == 0) {
                    alert('您至少要选中一条记录');
                    return false;
                }

                if (confirm('确定要删除这些广告吗？')) {
                    var checked_id = $(".checked_id:checked").serialize();

                    $.ajax({
                        type: "POST",
                        url: "{{:U('delete_all')}}",
                        data: checked_id,
                        success: function (data) {
                            if (data.status == 1) {
                                alert(data.msg);
                                window.location.reload();
                            }
                        }
                    })
                }
                return false;
            })
            //AJAX删除单条记录
            $(".del_one").click(function () {
                var id = $(this).parents('tr').data('id');
                var _this = $(this);
                if (confirm('确定要删除此条广告吗？')) {
                    $.ajax({
                        type: "POST",
                        url: "{{:U('delete_one')}}",
                        data: id,
                        success: function (data) {
                            if (data.status == 1) {
                                alert(data.msg);
                                _this.parents('tr').fadeOut(400);
                                window.location.reload();
                            }
                        }
                    })
                }
                return false;
            })
        })
    </script>
</block>
